package skiplist;

import java.util.Scanner;

public class TestSkipList {

    public static void main(String[] args) {
        SkipList zsl = SkipListUtil.zslCreate();
        initOneZsl(zsl);
        while (true) {
            SkipListUtil.zslPrint(zsl);
            Scanner scanner = new Scanner(System.in);
            System.out.println("1.增加 2.删除 3.查看");
            System.out.print("请输入要选择的操作：");
            int action = scanner.nextInt();
            int score;
            switch (action) {
                case 1 :
                    System.out.print("分数：");
                    score = scanner.nextInt();
                    System.out.print("值：");
                    String val = scanner.next();
                    SkipListUtil.zslInsert(zsl, score, val);
                    break;
                case 2:
                    System.out.print("分数：");
                    score = scanner.nextInt();
                    SkipListUtil.zslDeleteNode(zsl,score);
                    break;
                case 3:
                    System.out.print("分数：");
                    score = scanner.nextInt();
                    SkipListNode findX = SkipListUtil.zslFind(zsl, score);
                    System.out.println(findX == null ? "不存在" : "值为：" + findX.val);
            }
        }

    }

    public static void initOneZsl(SkipList zsl) {
        SkipListUtil.zslInsert(zsl, 7, "c");
        SkipListUtil.zslInsert(zsl, 7, "cc");
        SkipListUtil.zslInsert(zsl, 7, "asdf");
        SkipListUtil.zslInsert(zsl, 8, "a");
        SkipListUtil.zslInsert(zsl, 6, "e");
        SkipListUtil.zslInsert(zsl, 3, "c");
        SkipListUtil.zslInsert(zsl, 10, "pv");
        SkipListUtil.zslInsert(zsl, 4, "hh");
        SkipListUtil.zslInsert(zsl, 4, "d");
        SkipListUtil.zslInsert(zsl, 4, "dtt");
        SkipListUtil.zslInsert(zsl, 5, "aas");
        SkipListUtil.zslInsert(zsl, 11, "ad");
        SkipListUtil.zslInsert(zsl, 1, "af");
        SkipListUtil.zslInsert(zsl, 15, "if");
        SkipListUtil.zslInsert(zsl, 1, "aas");
        SkipListUtil.zslInsert(zsl, 14, "wei");
        SkipListUtil.zslInsert(zsl, 9, "aff");
        SkipListUtil.zslInsert(zsl, 13, "jhf");
        SkipListUtil.zslInsert(zsl, 2, "as");
        SkipListUtil.zslInsert(zsl, 16, "wer");
        SkipListUtil.zslInsert(zsl, 12, "sir");
    }

}
